package com.zklh.leetcode.tree.easy;

import com.zklh.leetcode.tree.model.TreeNode;

/**
 * @author ：tong nan
 * @date ：Created in 2021/4/21 17:25
 * @description ：反转树结构
 * @modifiedBy ：
 */
public class ReverseTree {

    public TreeNode reverseTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode node = root.left;
        root.left = root.right;
        root.right = node;
        reverseTree(root.left);
        reverseTree(root.right);
        return root;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(4);
        root.left = new TreeNode(2);
        root.right = new TreeNode(7);
        root.left.left = new TreeNode(1);
        root.left.right = new TreeNode(3);
        root.right.left = new TreeNode(6);
        root.right.right = new TreeNode(9);
        ReverseTree reverseTree = new ReverseTree();
        reverseTree.reverseTree(root);

    }

}
